package com.project.weimi.activity;

import com.project.weimi.R;
import com.project.weimi.utils.SetClickListener;

import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

/** 客服中心 */
public class ServiceCenterActivity extends BaseActivity {

	private RelativeLayout service_online, service_hotline, service_help, service_advise;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentViewWithBar(R.layout.activity_service_center, "客服中心");

		initView();
	}

	private void initView() {
		service_online = (RelativeLayout) findViewById(R.id.service_online);
		service_hotline = (RelativeLayout) findViewById(R.id.service_hotline);
		service_help = (RelativeLayout) findViewById(R.id.service_help);
		service_advise = (RelativeLayout) findViewById(R.id.service_advise);

		// 监听
		SetClickListener.setClickListener(listener, service_online, service_hotline, service_help, service_advise);
	}

	private OnClickListener listener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			Intent intent = null;

			switch (v.getId()) {
			case R.id.service_online: // 在线客服
				intent = new Intent(ServiceCenterActivity.this, ServiceOnlineActivity.class);
				startActivity(intent);
				break;
			case R.id.service_hotline: // 热线电话

				serviceHotline();
				break;
			case R.id.service_help: // 使用帮助
				intent = new Intent(ServiceCenterActivity.this, ServiceHelpActivity.class);
				startActivity(intent);
				break;
			case R.id.service_advise: // 意见反馈
				intent = new Intent(ServiceCenterActivity.this, FeedBackActivity.class);
				startActivity(intent);
				break;
			}

		}

		/** 热线电话 */
		private void serviceHotline() {
			View view = LayoutInflater.from(ServiceCenterActivity.this).inflate(R.layout.service_hotline_dialog, null);
			TextView dial = (TextView) view.findViewById(R.id.service_dial);
			TextView cancle = (TextView) view.findViewById(R.id.service_cancle);

			final AlertDialog dialog = new AlertDialog.Builder(ServiceCenterActivity.this).setView(view).create();
			dialog.show();

			dial.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					dialog.dismiss();

					Intent intent = new Intent(Intent.ACTION_DIAL);
					intent.setData(Uri.parse(getResources().getString(R.string.service_hotline)));
					if (intent.resolveActivity(getPackageManager()) != null) {
						startActivity(intent);
					}
				}
			});
			cancle.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					dialog.dismiss();
				}
			});
		}
	};

	@Override
	void setStatusBar(int statusBarColorRes) {
		super.setStatusBar(R.color.transparent_3);
	}

}
